<?php
class PaymentModule
{
	public function response()
	{
		global $_FANWE;
		$clss_name = ucfirst($_FANWE['request']['payment_name']);
		require FANWE_ROOT.'./ThinkPHP/Vendor/payment/'.$clss_name.'Payment.class.php';
		$payment_name = $clss_name."Payment";
		if(class_exists($payment_name))
		{
			$payment_model = new $payment_name;
			$res = $payment_model->dealResult();
			if($res['status'])
			{
				//响应处理成功
				showSuccess('支付成功',$res['info'],U('index/index'));
			}
			else 
			{
				showError('支付失败',$res['info'],U('index/index'));
			}
		}
		else 
		{
			showError('错误提示','支付失败',U('index/index'));
		}
	}
	
	public function chinabankcheck()
	{
		global $_FANWE;
		$payment = DB::fetchFirst('SELECT id,config,currency FROM '.DB::table('payment')." WHERE class_name='Chinabank'");
    	$payment['config'] = unserialize($payment['config']);
		$v_oid = trim($_FANWE['request']['v_oid']);
		
		if (empty($v_oid))
		 	$v_oid = trim($_FANWE['request']['v_oid']); 
		 	     
		$v_pstatus =trim($_FANWE['request']['v_pstatus']);      
		if (empty($v_pstatus))
		 	$v_pstatus = trim($_FANWE['request']['v_pstatus']); 
		 	     
		$v_amount  =trim($_FANWE['request']['v_amount']);     
		if (empty($v_amount))
		 	$v_amount = trim($_FANWE['request']['v_amount']);      
		
		$v_moneytype  =trim($_FANWE['request']['v_moneytype']);     
		if (empty($v_moneytype))
		 	$v_moneytype = trim($_FANWE['request']['v_moneytype']);      
		
		$v_md5str  =trim($_FANWE['request']['v_md5str']); 
		if (empty($v_md5str))
		 	$v_md5str = trim($_FANWE['request']['v_md5str']); 
		 			 
        /**
         * 重新计算md5的值
         */
        $key = $payment['config']['chinabank_key'];

        $md5string=strtoupper(md5($v_oid.$v_pstatus.$v_amount.$v_moneytype.$key));
    	        
        //开始初始化参数
        $log_id = $v_oid;
    	$money = $v_amount;
    	$payment_id = $payment['id']; 
        
		/* 检查秘钥是否正确 */
	    if ($v_md5str==$md5string)
	    {
	        if ($v_pstatus == '20')
	        {
	            $result = S('Payment')->paymentPaid($log_id,$money,$payment_id);
	            if ($result['status'] == true)
				{
	            	echo 'ok';
	            }
				else
				{
	            	echo 'error';
	            }
	        }
	    }
	    else
	    {
	          echo 'error';
	     }
	}
}
?>